
import java.util.LinkedList;

/* a synchronized queue */
public class Queue {

    /* the actual queue */
    private LinkedList<Object>  _queue ;

    /* the constructor - it simply creates the LinkedList where the queue elements are stored */
    public Queue() {
        _queue = new LinkedList<Object>();
    }

    
    /* gets the first element of the queue or blocks if the queue is empty */
    public synchronized Object dequeue() throws InterruptedException {
        while (_queue.isEmpty()) {
            wait();
        }
        return _queue.removeFirst();
    }

    /* add a new element to the queue */
    public synchronized void enqueue(Object obj) {

    	// If the queue does not already contain a copy of obj,
    	// and the queue has less than maxQueueSize element,
    	// then add it to our queue
    	if( (_queue.contains(obj) == false) ) {
	        _queue.addLast(obj);
	        notify();
    	}
    }
    
    public synchronized Boolean contains(Object obj) {
    	if(_queue.contains(obj)) {
    		return true;
    	} else {
    		return false;
    	}
    }

    public int size() {
    	return _queue.size();
    }

}
